package org.korosoft.rusalad.syncnrun.command;

import org.korosoft.rusalad.syncnrun.messaging.Messenger;

import java.io.IOException;
import java.io.Serializable;

/**
 * Syncnrun RPC command. This is the most trivial RPC command definition. See {@link MessageDrivenCommand} for
 * command with more sophisticated behavior.
 *
 * @author Dmitry Korotkov
 * @see MessageDrivenCommand
 * @since 1.0
 */
public interface Command<A extends Answer> extends Serializable {
    /**
     * Method execute is invoked on server side. It can use serializable properties as input parameters.
     * If a method throws an exception, {@link FailAnswer} is sent to client. Otherwise, return value is sent
     * to client in response to the command.
     * <p/>
     * This method may block if needed.
     *
     * @param messenger Messenger allows server implementation to send messages to client side.
     * @return Answer instance to send to client in response to the command.
     * @throws IOException When IO exception occurs
     */
    A execute(Messenger messenger) throws IOException;
}
